﻿-var entity = ViewData["entity"] as User
-var roles = ViewData["roles"] as IQueryable<Role>
-var notarialregisters = ViewData["notarialregisters"] as IQueryable<NotarialRegister>
-bool popup = ViewData.ContainsKey("popup")
-bool readOnly = ViewData.ContainsKey("readonly")
-if( ViewData.ContainsKey("popup") ) popup = true
-bool create = (entity.Id == 0)
-var userpermissions = (ViewData.ContainsKey("userpermissions")) ? ViewData["userpermissions"] as int[] : new int[0]
-var permissions = (ViewData.ContainsKey("permissions")) ? ViewData["permissions"] as List<Permission> : null
-var financepermissions = (ViewData.ContainsKey("financepermissions")) ? ViewData["financepermissions"] as List<Permission> : null
-var isMainNotarius = user.HasPermission("finance");
%form.validate{action="user.ivp/save",method="post"}
  _formfields
  =HTMLHelper.HiddenInput("id",entity.Id)
  -if(popup)
    =HTMLHelper.HiddenInput("popup",true)
  #content{class=(popup?"popup":"")}
    .formheader
      %h1
        %img.icon24{src="img/headericons/user.gif"}
        =(create)?"Новый сотрудник":entity.FullName
    _error
    -if (!popup)
      #tabs
        %ul
          %li
            %a#ageneral.selected{href="#",onclick="return setTab('general')"} Общие
          -if(!create)
            %li
              %a#apermissions{href="#",onclick="return setTab('permissions')"} Системные полномочия
            -if (user.HasPermission("financeadmin") || isMainNotarius)
              %li
                %a#afinancepermissions{href="#",onclick="return setTab('financepermissions')"} Финансовые полномочия
    .formbody
      .tab#general
        .field
          %table{width="700"}
            %tr
              %td{width="220"}            
                .field
                  %label.required{for="lastname"} Фамилия
                  %input#lastname.px215.big.basictext.required{name="lastname",value=HTMLHelper.EscapeQuotes(entity.LastName),maxlength="100"}
              %td{width="220"} 
                .field
                  %label.required{for="name"} Имя
                  %input#name.px215.big.basictext.required{name="name",value=HTMLHelper.EscapeQuotes(entity.Name),maxlength="100"}
              %td{width="220"} 
                .field
                  %label.required{for="patronymicname"} Отчество
                  %input#patronymicname.px215.big.basictext.required{name="patronymicname",value=HTMLHelper.EscapeQuotes(entity.PatronymicName),maxlength="100"}
        %table{width="465"}
          %tr
            %td{width="220"}
              .field
                %label{for="email"} Email
                %input#email.px215.email{name="email",value=entity.Email,maxlength="100"}
            %td{width="220"}
              .field
                %label{for="phone"} Телефон
                %input#phone.px215.phone{name="phone",value=entity.Phone,maxlength="100"}
        %table{width="465"}
          %tr
            %td{width="220"}
              .field
                %label.required{for="login"} Логин
                %input#login.px215.big.required{name="login",value=entity.Login,maxlength="100"}
            -if(!popup)
              %td{width="220"}
                .field
                  %label.required{for="password"} Пароль
                  -if( !create )
                    #pwdplaceholder
                      %a{href="#",onclick="javascript:$('#pwdplaceholder').hide();$('#newpwd').show();$('#password').attr('disabled',false); return false;"} Изменить
                    #newpwd.hidden
                      %input#password.px215.big.required.login{name="password",disabled="true",maxlength="50"}
                  -else
                    %input#password.px215.big.required.login{name="password",maxlength="50"}
                  .details Поле не используется если для системы настроена доменная авторизация
        .field
          %label.required{for="notarialregisterid"} Реестр по умолчанию
          =HTMLHelper.Select("notarialregisterid", notarialregisters, "name", "id", entity.NotarialRegisterId, "px215 required")         
        =HTMLHelper.HiddenInput("roleid",1)
        .field
          %label{for="comments"} Комментарии
          %textarea#comments.px685.basictext{name="comments",rows="2",maxlength="1000"}=entity.Comments
        -if(!popup)
          .field
            %label.radio{for="isarchive"}
              =HTMLHelper.Checkbox("isarchive","True","",entity.IsArchive)
              ="Архивный"
            .details Архивный сотрудник не может работать с системой.
        -else if(entity.IsArchive)
          .field Сотрудник в архиве
      -if (!create)
        .tab#permissions.hidden
          %h3 Системные полномочия:
            %ul.padded5.indent10
              -foreach(var p in permissions)
                -if (isMainNotarius || p.Alias != "financeadmin")
                  %li
                    -bool selected = userpermissions.Contains(p.Id)
                    %label.radio{for=String.Format("pid{0}",p.Id)}
                      =HTMLHelper.Checkbox("pid", p.Id, "", selected, true)
                      =p.Name
        -if (user.HasPermission("financeadmin") || isMainNotarius)
          .tab#financepermissions.hidden
            %h3 Доступ к отчетам:
              %ul.padded5.indent10
                -foreach(var p in financepermissions)
                  %li
                    -bool selected = userpermissions.Contains(p.Id)
                    %label.radio{for=String.Format("pid{0}",p.Id)}
                      =HTMLHelper.Checkbox("pid", p.Id, "", selected, true)
                      =p.Name                    
    .formbottom
      -if(!readOnly)
        %button.saveandreturn#submit{type="submit",onclick="$('#returnaftersave').val('true')"} Сохранить и вернуться
        %button.save#submit{type="submit",onclick="$('#returnaftersave').val('')"} Сохранить
      -if(!popup)
        %button.return{type="button",onclick="closeForm();"} Вернуться
      -else
        %button.return{type="button",onclick="self.close();"} Вернуться
-if(!popup)
  #rightmenu
